import 'package:async/async.dart';
import 'package:boss/common/common.dart';
import 'package:boss/main.dart';
import 'package:boss/models/store_income.dart';
import 'package:boss/ui/widget/loading/loading.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';

final GlobalKey linkKey = GlobalKey();

class HomeProvider extends ChangeNotifier {
  StoreIncome storeIncome;

  bool get isShowLoading => storeIncome == null;

  Future<Result<List>> initData() async {
    try {
      if (isShowLoading) showLoadingToast();
      var response = await api.queryStoreIncome();
      if (!response.successful()) {
        toast(response.msg);
        return Result.error(response.msg);
      }

      storeIncome = response.data;
      notifyListeners();

      return Result.value([]);
    } catch (e) {
      toast(e.toString());
      return Result.error(Constant.httpServeErrText);
    } finally {
      hideLoadingToast();
    }
  }

  clearData() {
    storeIncome = null;
  }
}
